package com.feilo.biz.impl;

import java.util.List;

import com.feilo.biz.ProductBiz;
import com.feilo.dao.ProductDao;
import com.feilo.dao.impl.ProductDaoImpl;
import com.feilo.entity.Product;

public class ProductBizImpl implements ProductBiz {
	ProductDao pd=new ProductDaoImpl();
	public void delete(Integer productid) {
		pd.delete(productid);

	}

	public Product getProduct(Integer productid) {
		return pd.find(productid);
	}

	@SuppressWarnings("unchecked")
	public List<Product> getProducts() {
		String hql="from Product order by id desc";
		List<Product> p=(List<Product>) pd.findByHQL(hql);
		return p;
	}

	public void save(Product product) {
		pd.save(product);

	}

	public void update(Product product) {
		pd.update(product);

	}
	@SuppressWarnings("unchecked")
	public List<Product> getProductsBySerch(String parm) {
		String hql="from Product where p_name like'"+"%"+parm+"%"+"'"+"order by id desc";
		List<Product> products= (List<Product>) pd.findByHQL(hql);
		return  products;
	}

	@SuppressWarnings("unchecked")
	public List<Product> getProducts(String parm) {
		String hql="from Product where p_type='"+parm+"' order by id desc";
		List<Product> p=(List<Product>) pd.findByHQL(hql);
		p.subList(0, 4);
		return p;
	}

}
